<template>
	<!-- 提醒消息列表 -->
	<Top-Page class="remind-msgs-box">
		<NavBar
			title="消息"
			leftText="返回"
			:class="navBar_class"
			@click-left="navBack()"
			@click-right="onClickRight"
			style="box-shadow: none; border-bottom: 1rpx solid #eeeeee"
		>
			<template #right>
				<view class="clear fs-28">清空</view>
			</template>
		</NavBar>

		<view class="list">
			<view
				class="list-item"
				:class="{'border-bottom-before':index!=list.length-1}"
				v-for="(item,index) in list"
				@click.stop="toDetailsMsg(item.trends_id)"
			>
				<user-avator :src="item.avatar"></user-avator>
				<view class="item-user">
					<view class="realname-date">
						<view class="realname"> {{ item.realname }} </view>

						<view class="date"> {{ item.date }} </view>
					</view>

					<view class="item-remark" v-if="item.type != 2">
						<view class="reply" v-if="item.reply">
							回复了
							<view class="reply-name">{{ item.reply }}：</view>
						</view>
						{{ item.remark }}
					</view>

					<view class="item-remark" v-else>
						<image
							class="star-img_icon"
							src="../../../static/image/friend/star-2.png"
						/>
					</view>
				</view>
			</view>
		</view>

		<!-- 		<view class="finished-text border-bottom-after" v-if="finished">
			{{ finished_text }}
		</view> -->
	</Top-Page>
</template>

<script>
	import NavBar from "@/components/NavBar/NavBar.vue";
	import { navBack } from "@/utils/utils.js";
	export default {
		data() {
			return {
				navBack: navBack,
				page: 0,
				finished: false,
				finished_text: "",
				list: [],
			};
		},
		components: { NavBar },
		created() {
			this.firstApi();
		},
		onReachBottom() {
			this.firstApi();
		},
		methods: {
			firstApi() {
				//没有更多了
				if (this.finished) {
					uni.showToast({
						title: "没有更多了",
						icon: "error",
					});
					return;
				}

				this.$api.friendCircleApi
					.circleRemindlog({
						page: ++this.page,
					})
					.then((res) => {
						const data = res.data ?? [];

						const msg = this.page === 1 ? "暂无信息" : "没有更多了";

						this.finished_text = msg;

						if (!data.length) this.finished = true;

						data.length && this.list.push(...data);
					});
			},
			//跳转信息详情
			toDetailsMsg(id) {
				uni.navigateTo({
					url: `/pages/friend/details-msg/details-msg?trends_id=${id}`,
				});
			},
			onClickRight() {
				this.$api.friendCircleApi.circleRemindclean().then((res) => {
					uni.showToast({
						title: `${res.msg}`,
						icon: "",
					});

					if (res.code == 0) {
						this.list.length = 0;
					}
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	@import "./index.scss";
</style>
